﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script src="../scripts/kindeditor/kindeditor-min.js" type="text/javascript"></script>
    <script src="../scripts/kindeditor/lang/zh_CN.js" type="text/javascript"></script>
    <link href="../scripts/kindeditor/themes/default/default.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=1005",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab = tabs.getTab("tab$1005");
                    tabs.removeTab(tab);
                }
            }
        });
        var uploadbutton;
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom: 0;">
        <table>
            <tr>
                <td>
                    链接名称：
                    <input class="mini-textbox" id="key" emptytext="关键字" />
                    类型：
                    <input id="state" class="mini-combobox" style="width: 90px;" data="HideAll" value="0"/>
                    <input class="mini-hidden" name="type" id="type" value="4"/>
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="search();">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-add" plain="true" onclick="addRow();">新增</a>
                    <a class="mini-button" iconcls="icon-remove" plain="true" onclick="delRows()">删除</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-unlock" plain="true" onclick="lockRows(0);">显示</a>
                    <a class="mini-button" iconcls="icon-lock" plain="true" onclick="lockRows(1)">隐藏</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true" sizeList="[15,20,50,100]" pageSize="15"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetLinkList" allowCellEdit="true" allowCellSelect="true">
            <div property="columns">
                <div type="checkcolumn">
                </div>
                <div cellCls="actionIcons" name="action" width="60px" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
                <div field="fl_title" width="150px" headeralign="center" align="center" allowsort="true" renderer="onNameRenderer">名称</div>
                <div field="fl_type" width="100px" headeralign="center" align="center" allowsort="true" renderer="onLinkTypeRenderer">所属网站</div>
                <div field="fl_hide" width="50px" headeralign="center" align="center" allowsort="true" renderer="onHideRenderer">状态</div>
                <div field="fl_orderid" width="50px" headeralign="center" align="center" allowsort="true">排序
                    <input property="editor" class="mini-textbox" style="width:100%;" vtype="int" onvalidation="onOrderValidation"/>
                </div>
                <div field="fl_url" headeralign="center" align="center" allowsort="true">链接地址</div>
                <div field="fl_pic" width="50px" headeralign="center" align="center" allowsort="true" renderer="onPicRenderer">图片</div>
                <div field="fl_hits" width="100px" headeralign="center" align="center" allowsort="true">点击数</div>
                <div field="fl_inserttime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">添加时间</div>
            </div>
        </div>
    </div>
    <div id="editWindow" class="mini-window" title="友情链接信息" style="width: 400px;" showmodal="true"
        allowresize="false" allowdrag="true" showFooter="true">
        <div id="editform" class="form">
            <input class="mini-hidden" name="fl_no" id="fl_no" />
            <table style="width: 98%; height: 100%;">
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>所属网站：
                    </td>
                    <td class="tdtext">
                        HR协会子网站
                        <input name="fl_type" class="mini-hidden" value="4" />
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle" style="width: 30%;">
                        <span class="red">*</span>名称：
                    </td>
                    <td class="tdtext">
                        <input name="fl_title" class="mini-textbox" required="true" style="width:180px;"/>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>链接地址：
                    </td>
                    <td class="tdtext">
                        <input name="fl_url" class="mini-textbox" required="true" vtype="url" style="width:180px;" value="http://"/>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        链接图片：
                    </td>
                    <td class="tdtext">
                        <input class="mini-hidden" name="fl_pic" id="fl_pic" />
                        <span id="spanload" style="display:none;">已经上传，<a id="img" class="linelink" target="_blank">查看</a>&nbsp;&nbsp;<a class="mini-button" iconcls="icon-remove" onclick="onDelete">删除</a></span>&nbsp;&nbsp;<input type="button" id="uploadButton" value="上传" />
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>排序：
                    </td>
                    <td class="tdtext">
                        <input name="fl_orderid" class="mini-textbox" value="0" required="true" vtype="int"/>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>状态：
                    </td>
                    <td class="tdtext">
                        <input name="fl_hide" class="mini-radiobuttonlist" data="Hide" value="0" required="true" />
                    </td>
                </tr>
            </table>
        </div>
        <div property="footer" style="text-align:center;padding:5px;">
            <a class="mini-button" style="width:60px;" onclick="updateRow()">保存</a>
            <span style="display:inline-block;width:25px;"></span>
            <a class="mini-button" style="width:60px;" onclick="closewin()">关闭</a>
        </div>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();

        var grid = mini.get("datagrid1");
        search();

        function search() {
            var key = mini.get("key").getValue();
            var state = mini.get("state").getValue();
            var type = mini.get("type").getValue();
            grid.load({ key: key, state: state, type: type });
            grid.sortBy("fl_orderid", "desc");
        }

        function onNameRenderer(e) {
            var record = e.record;
            var s = '<a class="linelink" target="_blank" href="' + record.fl_url + '">' + record.fl_title + '</a>';
            return s;
        }

        function onOrderValidation(e) {
            grid.commitEdit();
            var rowData = grid.getChanges();
            if (rowData.length > 0) {
                mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });
                var v = 0;
                if (e.isValid) {
                    if (e.value > 0)
                        v = e.value;
                }
                $.ajax({
                    url: "../data/system.aspx?method=TopLink",
                    data: { id: rowData[0].fl_no, order: v },
                    success: function (ret) {
                        mini.unmask(document.body);
                        if (ret == "out") {
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        if (ret == 1) {
                            ShowMessage("系统提示", "友情链接排序成功！", 1);
                            grid.reload();
                        }
                        else if (ret == 0) {
                            ShowMessage("系统提示", "该友情链接已不存在，请确认！", 2);
                            grid.reload();
                        }
                        else
                            ShowMessage("系统提示", "友情链接排序失败！", 3);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        mini.unmask(document.body);
                        ShowMessage("系统提示", "友情链接排序失败！", 3);
                    }
                });
            }
        }

        function onPicRenderer(e) {
            var record = e.record;
            var s = '未上传';
            if (record.fl_pic != null && record.fl_pic != '')
                s = '<a class="linelink" target="_blank" href="' + record.fl_pic + '">查看</a>';
            return s;
        }

        function addRow() {
            var form = new mini.Form("#editform");
            form.reset();
            form.loading();
            form.unmask();
            var win = mini.get("editWindow");
            win.setTitle("新增友情链接信息<span class='red'>( 带 * 号的必须填写)</span>");
            if (!win.visible)
                win.show();
            if (uploadbutton == null) {
                uploadbutton = KindEditor.uploadbutton({
                    button: KindEditor('#uploadButton')[0],
                    fieldName: 'imgFile',
                    url: '../scripts/kindeditor/upload/upload_json.ashx?dir=image',
                    afterUpload: function (data) {
                        if (data.error == 0) {
                            $("#img").attr("href", data.url);
                            $(".ke-button").val("重新上传");
                            mini.get("fl_pic").setValue(data.url);
                            $("#spanload").show();
                        } else
                            ShowMessage("系统提示", data.message, 2);
                    },
                    afterError: function (str) {
                        ShowMessage("系统提示", "上传失败！", 3);
                    }
                });
                uploadbutton.fileBox.change(function (e) {
                    uploadbutton.submit();
                });
            }
            else
                onDelete();
        }

        function editRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var win = mini.get("editWindow");
                var form = new mini.Form("#editform");
                $.ajax({
                    url: "../data/system.aspx?method=GetLink&id=" + row.fl_no,
                    success: function (text) {
                        if (text == "out") {
                            win.hide();
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        form.unmask();
                        var o = mini.decode(text);
                        form.setData(o);
                        win.setTitle("编辑友情链接信息<span class='red'>( 带 * 号的必须填写)</span>");
                        win.show();
                        if (uploadbutton == null) {
                            uploadbutton = KindEditor.uploadbutton({
                                button: KindEditor('#uploadButton')[0],
                                fieldName: 'imgFile',
                                url: '../scripts/kindeditor/upload/upload_json.ashx?dir=image',
                                afterUpload: function (data) {
                                    if (data.error == 0) {
                                        $("#img").attr("href", data.url);
                                        $(".ke-button").val("重新上传");
                                        mini.get("fl_pic").setValue(data.url);
                                        $("#spanload").show();
                                    } else
                                        ShowMessage("系统提示", data.message, 2);
                                },
                                afterError: function (str) {
                                    ShowMessage("系统提示", "上传失败！", 3);
                                }
                            });
                            uploadbutton.fileBox.change(function (e) {
                                uploadbutton.submit();
                            });
                        }
                        if (o.fl_pic != null && o.fl_pic != '') {
                            $("#img").attr("href", o.fl_pic);
                            $(".ke-button").val("重新上传");
                            $("#spanload").show();
                        }
                        else
                            onDelete();
                    },
                    error: function () {
                        ShowMessage("系统提示", "表单加载出错！", 3);
                        form.unmask();
                    }
                });
            }
        }

        function updateRow() {
            var form = new mini.Form("#editform");
            form.validate();
            if (form.isValid() == false)
                return;
            var o = form.getData();
            var json = mini.encode(o);

            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });
            $.ajax({
                url: "../data/system.aspx?method=SaveLink",
                data: { data: json },
                success: function (ret) {
                    mini.unmask(document.body);
                    if (ret == "out") {
                        var loginWindow = parent.mini.get("loginWindow");
                        if (!loginWindow.visible)
                            loginWindow.show();
                        return;
                    }
                    var editWindow = mini.get("editWindow");
                    if (ret == 1) {
                        editWindow.hide();
                        ShowMessage("系统提示", "友情链接保存成功！", 1);
                        grid.reload();
                    }
                    else if (ret == 0) {
                        editWindow.hide();
                        ShowMessage("系统提示", "该友情链接已不存在，请确认！", 2);
                        grid.reload();
                    }
                    else if (ret == 2) {
                        editWindow.hide();
                        ShowMessage("系统提示", "该友情链接已存在，请确认！", 2);
                    }
                    else
                        ShowMessage("系统提示", "友情链接保存失败！", 3);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    mini.unmask(document.body);
                    ShowMessage("系统提示", "友情链接保存失败！", 3);
                }
            });
        }

        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                mini.confirm("确定删除此友情链接？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            $.ajax({
                                url: "../data/system.aspx?method=DeleteLink",
                                type: "post",
                                data: { id: row.fl_no },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "友情链接删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "友情链接删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "友情链接删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
        }

        function delRows() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                mini.confirm("确定删除所选友情链接？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].fl_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=DeleteLink",
                                type: "post",
                                data: { id: ids },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "友情链接删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "友情链接删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "友情链接删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要删除的友情链接！", 2);
        }

        function lockRows(state) {
            var rows = grid.getSelecteds();
            var msg = "隐藏";
            if (state == 0)
                msg = "显示";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选友情链接？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].fl_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=LockLink",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "友情链接" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "友情链接" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "友情链接" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要" + msg + "的友情链接！", 2);
        }

        function topRows(state) {
            var rows = grid.getSelecteds();
            var msg = "置顶";
            if (state == 0)
                msg = "取消置顶";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选友情链接？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].fl_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=TopLink",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "友情链接" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "友情链接" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "友情链接" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要" + msg + "的友情链接！", 2);
        }

        function closewin() {
            var win = mini.get("editWindow");
            win.hide();
        }

        function onDelete() {
            $("#img").attr("href", "");
            mini.get("fl_pic").setValue("");
            $(".ke-button").val("上传");
            $("#spanload").hide();
        }
    </script>
</body>
</html>